﻿package mortal.game.view.msgtips
{
    import com.gengine.utils.*;
    import com.greensock.*;
    import flash.display.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.component.gconst.*;

    public class TipsItem extends Sprite
    {
        private var _tipTxt:TextField;
        private var _timerKey:uint;
        private var _hideFun:Function;
        private var _hideAble:Boolean;
        private var _colorUpdated:Boolean;
        private var _easeIn:TweenMax;

        public function TipsItem()
        {
            mouseEnabled = false;
            mouseChildren = false;
            this._tipTxt = new TextField();
            this._tipTxt.multiline = true;
            this._tipTxt.autoSize = TextFieldAutoSize.LEFT;
            this._tipTxt.wordWrap = true;
            this._tipTxt.width = 180;
            this._tipTxt.selectable = false;
            this._tipTxt.mouseEnabled = false;
            this._tipTxt.textColor = 15263976;
            this._tipTxt.filters = [FilterConst.nameGlowFilter];
            addChild(this._tipTxt);
            return;
        }// end function

        public function get hideAble() : Boolean
        {
            return this._hideAble;
        }// end function

        public function get colorUpdated() : Boolean
        {
            return this._colorUpdated;
        }// end function

        private function onTimerOut() : void
        {
            this._hideAble = false;
            if (this._hideFun != null)
            {
                this._hideFun.call(this, this);
            }
            return;
        }// end function

        public function updateData(param1:String, param2:String = "#ffff00", param3:int = 0, param4:Function = null) : void
        {
            this._colorUpdated = false;
            this._tipTxt.htmlText = HTMLUtil.addColor(param1, param2);
            this._hideAble = param3 != 0;
            if (this.hideAble)
            {
                this._timerKey = setTimeout(this.onTimerOut, param3);
            }
            return;
        }// end function

        public function updateColor(param1:String = "#e8e8e8") : void
        {
            var _loc_2:* = HTMLUtil.removeHtml(this._tipTxt.htmlText);
            this._tipTxt.text = _loc_2;
            this._colorUpdated = true;
            return;
        }// end function

        public function easeIn() : void
        {
            this._tipTxt.y = 15;
            this._easeIn = TweenMax.to(this._tipTxt, 0.5, {y:0, onComplete:this.onEaseInEnd});
            return;
        }// end function

        public function killEaseIn() : void
        {
            this._tipTxt.y = 0;
            if (this._easeIn && this._easeIn.active)
            {
                this._easeIn.kill();
            }
            return;
        }// end function

        private function onEaseInEnd() : void
        {
            return;
        }// end function

        public function dispose() : void
        {
            this.killEaseIn();
            this._colorUpdated = false;
            this._hideAble = false;
            this._hideFun = null;
            clearTimeout(this._timerKey);
            return;
        }// end function

        override public function get height() : Number
        {
            if (this._tipTxt.textHeight > 50)
            {
                return 15;
            }
            return this._tipTxt.textHeight;
        }// end function

    }
}
